package com.jiangxiaofei.citycloud.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiangxiaofei.citycloud.R;
import com.jiangxiaofei.citycloud.activity.MainWebActivity;
import com.jiangxiaofei.citycloud.view.CircleLayout;
import com.jiangxiaofei.citycloud.view.CircleLinearLayout;
import com.jiangxiaofei.citycloud.view.CircleTextView;
import com.jiangxiaofei.citycloud.web.SonicJavaScriptInterface;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * @author JiangXFei
 * @update 17.11.21
 * @content 罗盘页面
 */

public class CompassFragment extends Fragment {

    @InjectView(R.id.bagua_img_taiji)
    ImageView baguaImgTaiji;
    @InjectView(R.id.bagua_img_bg)
    ImageView baguaImgBg;
    @InjectView(R.id.bagua_menu1_item1)
    CircleTextView baguaMenu1Item1;
    @InjectView(R.id.bagua_menu1_item2)
    CircleTextView baguaMenu1Item2;
    @InjectView(R.id.bagua_menu1_item3)
    CircleTextView baguaMenu1Item3;
    @InjectView(R.id.bagua_menu1_item4)
    CircleTextView baguaMenu1Item4;
    @InjectView(R.id.bagua_menu1_item5)
    CircleTextView baguaMenu1Item5;
    @InjectView(R.id.bagua_menu1_item6)
    CircleTextView baguaMenu1Item6;
    @InjectView(R.id.bagua_menu1_item7)
    CircleTextView baguaMenu1Item7;
    @InjectView(R.id.bagua_menu1_item8)
    CircleTextView baguaMenu1Item8;
    @InjectView(R.id.bagua_clinear_menu1)
    CircleLayout baguaClinearMenu1;
    @InjectView(R.id.bagua_menu2_item1)
    TextView baguaMenu2Item1;
    @InjectView(R.id.bagua_menu2_item2)
    TextView baguaMenu2Item2;
    @InjectView(R.id.bagua_menu2_item3)
    TextView baguaMenu2Item3;
    @InjectView(R.id.bagua_menu2_item4)
    TextView baguaMenu2Item4;
    @InjectView(R.id.bagua_menu2_item5)
    TextView baguaMenu2Item5;
    @InjectView(R.id.bagua_menu2_item6)
    TextView baguaMenu2Item6;
    @InjectView(R.id.bagua_menu2_item7)
    TextView baguaMenu2Item7;
    @InjectView(R.id.bagua_menu2_item8)
    TextView baguaMenu2Item8;
    @InjectView(R.id.bagua_clinear_menu2)
    CircleLinearLayout baguaClinearMenu2;
    @InjectView(R.id.bagua_tv_taiji)
    TextView baguaTvTaiji;
    private View serviceView;

    private Animation circle_anim;
    private Animation alphaAnimation;
    private Activity mActivity;
    private Context mContext;
    private final String http = "http://www.cbczhuyun.com/";

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        serviceView = inflater.inflate(R.layout.fragment_bagua_layout, null);
        ButterKnife.inject(this, serviceView);
        mActivity = getActivity();
        mContext = getActivity();
        initAnima();


        return serviceView;
    }

    private void initAnima() {
        circle_anim = AnimationUtils.loadAnimation(mContext, R.anim.taiji_scale);
        LinearInterpolator interpolator = new LinearInterpolator();  //设置匀速旋转，在xml文件中设置会出现卡顿
        circle_anim.setInterpolator(interpolator);
        baguaClinearMenu1.setVisibility(View.VISIBLE);
        baguaClinearMenu2.setVisibility(View.VISIBLE);
        alphaAnimation = new AlphaAnimation(1, 0.4f);
        alphaAnimation.setDuration(1000);
        alphaAnimation.setInterpolator(new LinearInterpolator());
        alphaAnimation.setRepeatCount(Animation.INFINITE);
        alphaAnimation.setRepeatMode(Animation.REVERSE);
        baguaImgTaiji.startAnimation(circle_anim);
    }

    @OnClick({R.id.bagua_img_taiji, R.id.bagua_tv_taiji,
            R.id.bagua_menu1_item1, R.id.bagua_menu1_item2
            , R.id.bagua_menu1_item3, R.id.bagua_menu1_item4, R.id.bagua_menu1_item5
            , R.id.bagua_menu1_item6, R.id.bagua_menu1_item7, R.id.bagua_menu1_item8,
            R.id.bagua_menu2_item1, R.id.bagua_menu2_item2
            , R.id.bagua_menu2_item3, R.id.bagua_menu2_item4, R.id.bagua_menu2_item5
            , R.id.bagua_menu2_item6, R.id.bagua_menu2_item7, R.id.bagua_menu2_item8})
    public void OnClick(View v) {
        Intent intent;
        String url = "";
        String title = "";
        switch (v.getId()) {
            case R.id.bagua_tv_taiji:
//            case R.id.bagua_img_taiji:
//                title = "城市罗盘";
//                url = http + "front/loupan?username=ccc&password=123456&checkcode=www_kem1network_com" +
//                        "&title=城市沙盘&city_id=370200";
//                startWeb(url, title);
                break;
            case R.id.bagua_menu1_item1:
                title = mActivity.getString(R.string.menu1_item1);
                url = http + "front/content?username=ccc&password=123456&checkcode=www_kem1network_com&title=城市沙盘&city_id=370200";
                startWeb(url, title);
                break;
            case R.id.bagua_menu1_item2:
                title = mActivity.getString(R.string.menu1_item2);
                url = http + "front/safe?username=ccc&password=123456&checkcode=www_kem1network_com" +
                        "&title=城市消防&city_id=370200";
                startWeb(url, title);
                break;
            case R.id.bagua_menu1_item3:
                title = mActivity.getString(R.string.menu1_item3);
                url = http + "front/shequ?username=ccc&password=123456&checkcode=www_kem1network_com" +
                        "&title=城市住区服务&city_id=370200";
                startWeb(url, title);
                break;
            case R.id.bagua_menu1_item4:
                title = mActivity.getString(R.string.menu1_item4);
                url = http + "front/dongli?username=ccc&password=123456&checkcode=www_kem1network_com" +
                        "&title=城市动力节能&city_id=370200";
                startWeb(url, title);
                break;
            case R.id.bagua_menu1_item5:
                title = mActivity.getString(R.string.menu1_item5);
                url = http + "front/zhinao?username=ccc&password=123456&checkcode=www_kem1network_com" +
                        "&title=城市智脑&city_id=370200";
                startWeb(url, title);
                break;
            case R.id.bagua_menu1_item6:
                title = mActivity.getString(R.string.menu1_item6);
                url = http + "front/dixiakongjian?username=ccc&password=123456&checkcode=www_kem1network_com" +
                        "&title=城市地下空间&city_id=370200";
                startWeb(url, title);
                break;
            case R.id.bagua_menu1_item7:
                title = mActivity.getString(R.string.menu1_item7);
                url = http + "front/loupan?username=ccc&password=123456&checkcode=www_kem1network_com" +
                        "&title=城市楼盘&city_id=370200";
                startWeb(url, title);
                break;
            case R.id.bagua_menu1_item8:
                title = mActivity.getString(R.string.menu1_item8);
                url = "http://www.cbczhuyun.com/Premiere/WebShow/bianmin.html";
                startWeb(url, title);
                break;


            case R.id.bagua_menu2_item1:
                url = "http://www.cbczhuyun.com/Premiere/WebShow/xiaqu.html";
                title = mActivity.getString(R.string.menu2_item1);
                startWebShu(url, title);
                break;
            case R.id.bagua_menu2_item2:
                url = "http://www.cbczhuyun.com/Premiere/WebShow/zhongjian.html";
                title = mActivity.getString(R.string.menu2_item2);
                startWebShu(url, title);
                break;
            case R.id.bagua_menu2_item3:
                url = "http://211.95.11.159:9091/sdunicom/index.htm";
                title = mActivity.getString(R.string.menu2_item3);
                startWebShu(url, title);
                break;
            case R.id.bagua_menu2_item4:
                url ="http://www.cbczhuyun.com/Premiere/WebShow/peixun.html";
                title = mActivity.getString(R.string.menu2_item4);
                startWebShu(url, title);
                break;
            case R.id.bagua_menu2_item5:
                url = "http://www.cbczhuyun.com/Premiere/WebShow/zhinan.html";
                title = mActivity.getString(R.string.menu2_item5);
                startWebShu(url, title);
                break;
            case R.id.bagua_menu2_item6:
                url = "https://www.nbimer.com/";
                title = mActivity.getString(R.string.menu2_item6);
                startWebShu(url, title);
                break;
            case R.id.bagua_menu2_item7:
                url = "http://www.feyboo.com/";
                title = mActivity.getString(R.string.menu2_item7);
                startWebShu(url, title);
                break;
            case R.id.bagua_menu2_item8:
                url = "http://www.cbczhuyun.com/Premiere/WebShow/bianmin.html";
                title = mActivity.getString(R.string.menu2_item8);
                startWebShu(url, title);
                break;
            default:
                break;
        }
    }

    private void startWeb(String url, String title) {
        Intent intent;
        intent = new Intent(mContext, MainWebActivity.class);
        intent.putExtra(MainWebActivity.PARAM_URL, url);
        intent.putExtra(MainWebActivity.PARAM_TITLE, title);
        intent.putExtra(SonicJavaScriptInterface.PARAM_CLICK_TIME, System.currentTimeMillis());
        intent.putExtra(MainWebActivity.PARAM_TYPE, "heng");
        startActivity(intent);
    }

    private void startWebShu(String url, String title) {
        Intent intent;
        intent = new Intent(mContext, MainWebActivity.class);
        intent.putExtra(MainWebActivity.PARAM_URL, url);
        intent.putExtra(SonicJavaScriptInterface.PARAM_CLICK_TIME, System.currentTimeMillis());
        intent.putExtra(MainWebActivity.PARAM_TITLE, title);
        startActivity(intent);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
